package com.zy.mobile.message.push.faio;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

import com.zy.mobile.message.push.bio.BioTimeServerHandler;

/**
 * 伪异步IO
 * @author zhangyi
 *
 */
public class FAioTimeServer {
	
	public static void main(String[] args) throws IOException {
		int port = 8080;
		if(args!=null && args.length>0){
			try {
				port = Integer.valueOf(args[0]);
				
			} catch (Exception e) {
				// TODO: handle exception
			}		
		}
		ServerSocket server = null;
		try {
			server = new ServerSocket(port);
			System.out.println("the time server is start in port : "+port);
			Socket socket = null;
			TimeServerHandlerExcutePool singleExecutor = new TimeServerHandlerExcutePool(50,10000);
			while(true){
				socket = server.accept();
				singleExecutor.excute(new BioTimeServerHandler(socket));
			}
		} catch (Exception e) {
			// TODO: handle exception
		} finally{
			if(server!=null){
				System.out.println("the time server close");
				server.close();
				server =null;
			}
		}
	}
}
